package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.LeaseAgreementService;
import com.atguigu.lease.web.app.vo.agreement.AgreementDetailVo;
import com.atguigu.lease.web.app.vo.agreement.AgreementItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;

    @Autowired
    GraphInfoMapper graphInfoMapper;


    @Override
    public List<AgreementItemVo> listItem(String phone) {
        return leaseAgreementMapper.listItem(phone);
    }

    @Override
    public AgreementDetailVo getDetailByID(Long id) {
        //查询租约基本信息和房间等相关信息
        AgreementDetailVo agreementDetailVo = leaseAgreementMapper.getDetailById(id);
        // 公寓的信息
        List<GraphInfo> graphInfosApart = graphInfoMapper.selectGraphInfoByIdAndType(agreementDetailVo.getApartmentId(), ItemType.APARTMENT);
        // 房间的信息
        List<GraphInfo> graphInfosRoom = graphInfoMapper.selectGraphInfoByIdAndType(agreementDetailVo.getRoomId(), ItemType.ROOM);
        agreementDetailVo.setApartmentGraphVoList(graphInfosApart);
        agreementDetailVo.setRoomGraphVoList(graphInfosRoom);
        return agreementDetailVo;
    }
}




